<?php

use yii\db\Migration;
use yii\db\Schema;

class m170714_023120_ADD_TABLE_FINANCE extends Migration
{
    public function up()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

        // 财务审批信息表 (主表)
        $this->createTable('finance', [
            "id" =>         Schema::TYPE_PK,
            "type" =>  		Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '类型  1 收款 2 退款'",
            "price_type" => Schema::TYPE_INTEGER.   "(2) DEFAULT  '0' COMMENT '付款方式  1 现金 2 汇款 3 支付宝 ...'",
            //"order_id" =>	Schema::TYPE_INTEGER.   "(11) NULL  COMMENT '对应订单ID'",
            //"price" =>    Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '金额'",
            "company" =>	Schema::TYPE_STRING.    "(128) NULL COMMENT '收(付)款单位'",
            "account" =>	Schema::TYPE_STRING.    "(128) NULL COMMENT '收(付)款账号'",
            "name" =>		Schema::TYPE_STRING.    "(16) NULL COMMENT '收(付)款姓名'",
            "desc" =>       Schema::TYPE_STRING.    "(1024) NULL COMMENT '备注'",
            "img" =>		Schema::TYPE_STRING.    "(128) NULL COMMENT '汇款单'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1提交  2 操作审批  3  财务审批'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '申请人'",
            "created_at" => Schema::TYPE_DATETIME. " NULL  COMMENT '申请时间'",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

        // 财务审批信息表 (子表) 1 vs 多
        $this->createTable('finance_order', [
            "id" =>         Schema::TYPE_PK,
            "order_id" =>	Schema::TYPE_INTEGER.   "(11) NULL  COMMENT '对应订单ID'",
            "price" =>      Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '金额'",
        ], $tableOptions);

    }

    public function down()
    {
        echo "m170714_023120_ADD_TABLE_FINANCE cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
